/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.order.model;

import cn.ekuma.data.ui.swing.AbstractDTOTableModel;

import com.openbravo.format.Formats;

import com.openbravo.bean.erp.Order;
import com.openbravo.bean.erp.viewbean.OrderLine_V;
import com.openbravo.pos.base.AppLocal;

/**
 * 
 * @author Administrator
 */
public class OrderLineVTableModel extends AbstractDTOTableModel<OrderLine_V> {
	public static String[] TABLECOLUMNS_OrderLine = new String[] {
			AppLocal.getIntString("label.orderid"),
			AppLocal.getIntString("label.ordertype"),
			AppLocal.getIntString("label.ordertypedialog.bearing"),
			AppLocal.getIntString("label.date"),
			AppLocal.getIntString("label.customer"),
			AppLocal.getIntString("label.location"),
			AppLocal.getIntString("Menu.Users"),
			AppLocal.getIntString("label.units"),
			AppLocal.getIntString("label.orderline.price"),
			AppLocal.getIntString("label.orderline.defprice"),
			AppLocal.getIntString("label.orderline.consultUnits"),
			AppLocal.getIntString("label.attribute") };

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		OrderLine_V value = getObj(rowIndex);
		switch (columnIndex) {
		case 0:
			return value.getOrderId();
		case 1:
			return value.getDefineType();
		case 2:
			if (value.getOrdertype() == Order.ORDERBEARING_NORMAL)
				return AppLocal.getIntString("label.orderbearing.normal");
			return AppLocal.getIntString("label.orderbearing.reverse");
		case 3:
			return Formats.TIMESTAMP.formatValue(value.getDate());
		case 4:
			return value.getCustomer();
		case 5:
			return value.getLocation();
		case 6:
			return value.getName();
		case 7:
			return value.getMultiply();
		case 8:
			return Formats.CURRENCY.formatValue(value.getPrice());
		case 9:
			return Formats.CURRENCY.formatValue(value.getDefaultPrice());
		case 10:
			return value.getConsulMultiply();
		case 11:
			return value.getAttributeset();
		}
		return null;
	}

	public static String getOrderLineInfoDescription(OrderLine_V orderLine) {
		String buildStr = TABLECOLUMNS_OrderLine[0] + ":"
				+ orderLine.getOrderId() + "\n" + TABLECOLUMNS_OrderLine[1]
				+ ":" + orderLine.getDefineType() + "\n"
				+ TABLECOLUMNS_OrderLine[4] + ":" + orderLine.getCustomer()
				+ "\n" + TABLECOLUMNS_OrderLine[5] + ":"
				+ orderLine.getLocation() + "\n" + TABLECOLUMNS_OrderLine[6]
				+ ":" + orderLine.getName() + "\n" + TABLECOLUMNS_OrderLine[7]
				+ ":" + orderLine.getMultiply() + "\n"
				+ TABLECOLUMNS_OrderLine[8] + ":" + orderLine.getPrice() + "\n"
				+ TABLECOLUMNS_OrderLine[9] + ":" + orderLine.getDefaultPrice()
				+ "\n" + TABLECOLUMNS_OrderLine[10] + ":"
				+ orderLine.getConsulMultiply() + "\n"
				+ TABLECOLUMNS_OrderLine[11] + ":"
				+ orderLine.getAttributeset();

		return buildStr;
	}

	@Override
	public String[] getColumnNames() {
		return TABLECOLUMNS_OrderLine;
	}
}